package com.lj.ljminsu.configuration;

import com.lj.ljminsu.interceptor.LoginInterceptor;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class AppConfiguration implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Bean
    @LoadBalanced
    public RestTemplate provideRestTemplate(){
        return new RestTemplate();
    }

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/user/securityCode")//放行手机验证码请求
                .excludePathPatterns("/yan/getVerifiCode")//放行图片验证码请求
                .excludePathPatterns("/user/login")//放行普通登录请求
                .excludePathPatterns("/user/phoneCode")//放行手机验证码登录请求
                .excludePathPatterns("/user/register")//放行注册请求
                .excludePathPatterns("/user/resetPwdForm");//放行重置密码请求
    }
}
